﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace common
{
    public class EqualityLambda<T>: IEqualityComparer<T>
    {
        Func<T ,T ,bool> comparer;
        Func<dynamic, dynamic, bool> comparerDynamic;
        public EqualityLambda(Func<T, T, bool> compare,Func<dynamic, dynamic, bool> compareDynamic)
        {
            comparer=compare;
            comparerDynamic=compareDynamic;
        }
        public bool  Equals(T x, T y)
        {
            if(comparer != null)
 	            return comparer(x,y);

            if (comparerDynamic != null)
                return comparerDynamic(x, y);

            //maybe throw an error?
            return false;
        }

        public int  GetHashCode(T obj)
        {
 	        return obj.GetHashCode();
        }
    }
}